/**
 *  @file SDLHighScoreView.cpp
 *
 *  @date 22-dec-2009
 *  @author Ives van der Flaas
 */

#include <sstream>
#include <cassert>
#include "SDLHighScoreView.h"
#include "SDLTextRepresentation.h"
#include "SDLZoomDrawer.h"


namespace si_sdl
{

SDLHighScoreView::SDLHighScoreView()
{


}

SDLHighScoreView::~SDLHighScoreView()
{

}

void SDLHighScoreView::draw()
{
	assert(fNames != 0 && fScores != 0);

	si::Vector2 realscreen = SDLZoomDrawer::get()->requestDrawableRegion();

	const int horizontalMargin = 80;
	const int topMargin = 80;

	fNames->draw(
				si::Vector2(horizontalMargin,topMargin),
				si::Vector2(0,0));

	fScores->draw(
				si::Vector2(realscreen.getX()-horizontalMargin-fScores->getSize().getX(), topMargin),
				si::Vector2(0,0));
}

void SDLHighScoreView::setText(std::vector<std::string> names, std::vector<int> scores)
{
	std::vector<std::string> scoreStrings;
	scoreStrings.reserve(scores.size());

	for(unsigned int i = 0; i < scores.size(); i++)
	{
		std::stringstream ss;
		ss << scores[i];
		std::string str;
		ss >> str;
		scoreStrings.push_back(str);
	}


	std::string nameString;
	for(unsigned int i = 0; i < names.size(); i++)
		nameString += names[i] + "\n";


	std::string scoreString;
	for(unsigned int i = 0; i < scoreStrings.size(); i++)
		scoreString += scoreStrings[i] + "\n";

	const int textSize = 20;
	fNames = std::tr1::shared_ptr<si::Representation>(
				new SDLTextRepresentation(
						nameString,
						"fonts/Vera.ttf",
						textSize,
						Color(255,255,255),
						Color(0,0,0),
						ALIGN_LEFT));

	fScores = std::tr1::shared_ptr<si::Representation>(
			new SDLTextRepresentation(
					scoreString,
					"fonts/Vera.ttf",
					textSize,
					Color(255,255,255),
					Color(0,0,0),
					ALIGN_RIGHT));
}
}
